2000W / 48V LLC Battery-Charger  V1.00
L1_Math_Funktionen.c
Go to the documentation of this file.
1 /**********************************************************/
20 /* Einbindung externer Module (include) ------------*/
21 #include "StandardTypes.h"
22 #include "Preprocess.h"
23 #include "L1_Math_Funktionen.h"
24 
25 /**********************************************************/
26 /*** Lokale Konstanten und Makros (define) ***/
27 /**********************************************************/
28 
29 
30 
31 /**********************************************************/
32 /*** Lokale Typen und Strukturen (typedef) ***/
33 /**********************************************************/
34 
35 
36 
37 /**********************************************************/
38 /*** Lokale Variablen (Definition) ***/
39 /**********************************************************/
40 
41 
42 
43 /**********************************************************/
44 /*** Globale Variablen (Definition) ***/
45 /**********************************************************/
46 
47 
48 
49 /**********************************************************/
50 /*** Lokale Funktionsprototypen (Deklaration) ***/
51 /**********************************************************/
52 
53 
54 
55 /**********************************************************/
56 /*** Lokale Funktionen (Implementation) ***/
57 /**********************************************************/
58 
59 
60 
61 /**********************************************************/
62 /*** Globale Funktionen (Implementation) ***/
63 /**********************************************************/
64 /**********************************************************/
71 SI_16 L1_PT1_Element(ST_PT1_ELEMENT *pstPt1Feld, SI_16 s16Input)
72 {
73 ST_PT1_ELEMENT stPt1Work;
74 
75  /* Speicher = Speicher + Zeitkonstante * (Input-Speicher[Highteil]) */
76 
77  stPt1Work=*pstPt1Feld; /* lade Feld in Arbeitsregister */
78  /* Filter Berechnung */
79  stPt1Work.s32Speicher+=stPt1Work.s16DtT*(s16Input-(stPt1Work.s32Speicher>>16));
80  *pstPt1Feld=stPt1Work; /* speichere Ergebnis in die Strukturvariable */
81  return(stPt1Work.s32Speicher>>16); /* Rückgabewert = Speicher[Highteil] */
82 
83 } /* Ende L1_PT1_Element */
84 
85 /**********************************************************/
96 SI_16 L1_PI_Regler(ST_PI_WERTE *pstPiWerte, ST_PI_PARAMETER stPiParameter)
97 {
98 SI_32 s32Ergebnis;
99 ST_PI_WERTE stPiWork;
100 
101  /* Fehler = Sollwert - Istwert */
102  /* Integral = Integral + Fehler * Ki */
103  /* Integral = MaxMin(Integral) */
104  /* Ausgang = 2^N * Fehler * Kp + Integral */
105  /* Ausgang = MaxMin(Ausgang) */
106 
107  s32Ergebnis=0;
108  stPiWork=*pstPiWerte; /* lade Feld in Arbeitsregister */
109  /* Regelabweichung bilden */
110  stPiWork.s16Error=stPiWork.s16Sollwert-stPiWork.s16Istwert;
111  /* Integrator */
112  stPiWork.s32Integral+=stPiWork.s16Error*stPiParameter.s16Ki;
113  /* Begrenzung Integralteil */
114  if((stPiWork.s32Integral>>15)>stPiParameter.s16Ymax) {stPiWork.s32Integral=(stPiParameter.s16Ymax<<15);} /* Maximum */
115  if((stPiWork.s32Integral>>15)<stPiParameter.s16Ymin) {stPiWork.s32Integral=(stPiParameter.s16Ymin<<15);} /* Minimum */
116  /* Proportionalanteil */
117  s32Ergebnis=stPiWork.s16Error*stPiParameter.s16Kp;
118  if(stPiParameter.s16Np>0) { /* zusätzliche Proportionalverstärkung */
119  if(s32Ergebnis>((16383*65536)>>stPiParameter.s16Np)) { /* positive Begrenzung */
120  s32Ergebnis=16383*65536;
121  }
122  else {
123  if(s32Ergebnis<((-16383*65536)>>stPiParameter.s16Np)) { /* negative Begrenzung */
124  s32Ergebnis=-16383*65536;
125  }
126  else {
127  s32Ergebnis<<=stPiParameter.s16Np; /* verstärke Proportionalanteil um 2^n */
128  }
129  }
130  }
131  /* Ausgang */
132  s32Ergebnis+=stPiWork.s32Integral;
133  /* Begrenzung Reglerausgang */
134  if((s32Ergebnis>>15)>stPiParameter.s16Ymax) {s32Ergebnis=(stPiParameter.s16Ymax<<15);} /* Maximum */
135  if((s32Ergebnis>>15)<stPiParameter.s16Ymin) {s32Ergebnis=(stPiParameter.s16Ymin<<15);} /* Minimum */
136  /* Reglerausgang */
137  stPiWork.s16Ausgang=s32Ergebnis>>15;
138  *pstPiWerte=stPiWork; /* speichere Ergebnis in die Strukturvariable */
139  return(s32Ergebnis>>15); /* Rückgabewert = Reglerausgang[Highteil] */
140 
141 } /* Ende L1_PI_Regler */
142 
143 
Typdefinition der ISLE Standard-Datentypen.
SI_16 L1_PT1_Element(ST_PT1_ELEMENT *pstPt1Feld, SI_16 s16Input)
Filter 1. Ordnung (PT1-Glied)
Bereitstellung oft verwendeter Mathematik-Funktionen (Filter, Regler, usw.)
Definitionen fuer Preprozessor-Anweisungen.
SI_16 L1_PI_Regler(ST_PI_WERTE *pstPiWerte, ST_PI_PARAMETER stPiParameter)
PI-Regler.
int32_t SI_32
Definition: StandardTypes.h:39
int16_t SI_16
Definition: StandardTypes.h:40